﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloverNet.Authorization
{
    public class RolePermissionProvider : IPermissionProvider
    {
        internal RolePermissionCollection _roles;
        public RolePermissionCollection Roles
        {
            get => _roles ?? (_roles = GetRoles());
        }

        internal static RolePermissionProvider _instance;

        public static RolePermissionProvider Current
        {
            get => _instance ?? new RolePermissionProvider();
            set => _instance = value;
        }

        public virtual RolePermissionCollection GetRoles()
        {
            return new RolePermissionCollection();
        }

        public virtual IEnumerable<object> GetPermissions()
        {
            return Current.Roles.SelectMany(m => m.Permissions);
        }

        IEnumerable<object> IPermissionProvider.GetPermissions()
        {
            return Current.GetPermissions();
        }
    }
}
